package rtc.core.net;

import java.nio.channels.SocketChannel;

/**
 * Created by Administrator on 2018/2/9.
 */

public interface CoreSocket {
    int STATE_DISCONNECTED = 0;
    int STATE_CONNECTING = 1;
    int STATE_CONNECTED = 2;

    int ERROR_NONE = 0;
    int ERROR_UNEXPECTED = 1000;
    int ERROR_CONNECT_TIME_OUT = 1001;
    int ERROR_CONNECT_FAILED = 1002;
    int ERROR_CHANNEL_READ = 1003;
    int ERROR_CHANNEL_WRITE = 1004;

    interface Callback{
        void onConnected();
        void onDisconnected();
        void onData(byte[] data);
        void onSelectorLoop(int count);
    }

    interface Transceiver{
        void reset();
        void onReadable(SocketChannel channel);
        int send(byte[] data, int offset, int length);
    }

    boolean connect(long timeout);

    void close();

    int send(byte[] data,int offset,int length);

    int state();
}
